package com.qf.student.controller;


import com.qf.student.response.R;
import com.qf.student.service.IStudentCourseService;
import com.qf.student.utils.TokenUtils;
import com.qf.student.vo.input.UpdateScoreInputVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author author
 * @since 2022-11-21
 */
@RestController
@RequestMapping("/student-course")
public class StudentCourseController {

    @Autowired
    private IStudentCourseService studentCourseService;

    @RequestMapping("/select-course/{courseId}")
    public R selectCourse(@PathVariable("courseId") Integer courseId, HttpServletRequest request) {
        Integer userId = TokenUtils.getUserId(request);
        return studentCourseService.selectCourse(courseId, userId);
    }

    @RequestMapping("/get-student-course")
    public R getStudentCourse(HttpServletRequest request) {
        Integer userId = TokenUtils.getUserId(request);
        return studentCourseService.getStudentCourse(userId);
    }

    @RequestMapping("/unselect-course/{courseId}")
    public R unselectCourse(@PathVariable("courseId") Integer courseId, HttpServletRequest request) {
        Integer userId = TokenUtils.getUserId(request);
        return studentCourseService.unselectCourse(userId, courseId);
    }

    @RequestMapping("/get-student-score")
    public R getStudentScore(HttpServletRequest request) {
        Integer userId = TokenUtils.getUserId(request);
        return studentCourseService.getStudentScore(userId);
    }

    @RequestMapping("/teacher-update-score")
    public R teacherUpdateScore(@Valid UpdateScoreInputVo updateScoreInputVo, HttpServletRequest request) {
        Integer userId = TokenUtils.getUserId(request);

        return studentCourseService.teacherUpdateScore(updateScoreInputVo, userId);
    }

}
